﻿Namespace nHibernate.Models
    Public Class AddressModel
        Public Sub New()
        End Sub

        Public Overridable Property CustomerID As String

        Public Overridable Property Salutation As String
        Public Overridable Property Title As String
        Public Overridable Property Forname As String
        Public Overridable Property Surname As String
        Public Overridable Property Street As String
        Public Overridable Property No As String
        Public Overridable Property Addition As String
        Public Overridable Property ZipCode As String
        Public Overridable Property City As String
        Public Overridable Property Country As String

        Public Overridable Property CompanyName As String

        Public Overrides Function ToString() As String
            Dim temp As String = ""

            If Not String.IsNullOrEmpty(CompanyName) Then
                temp += CompanyName
            Else
                If String.IsNullOrEmpty(Salutation) = False Then
                    temp = Salutation + " "
                End If
                If String.IsNullOrEmpty(Forname) = False OrElse String.IsNullOrEmpty(Surname) = False Then
                    If String.IsNullOrEmpty(Forname) Then
                        temp += Surname + ", "
                    Else
                        temp += Forname
                        If String.IsNullOrEmpty(Surname) = False Then
                            temp += " " + Surname + ", "
                        Else
                            temp += ", "
                        End If
                    End If
                End If
            End If


            If String.IsNullOrEmpty(Addition) = False Then
                temp += Addition + ", "
            End If
            If String.IsNullOrEmpty(Street) = False Then
                temp += Street
                If String.IsNullOrEmpty(No) = False Then
                    temp += " " + No + ", "
                Else
                    temp += ", "
                End If
            End If
            If String.IsNullOrEmpty(ZipCode) = False OrElse String.IsNullOrEmpty(City) = False Then
                If String.IsNullOrEmpty(ZipCode) Then
                    temp += City + ", "
                Else
                    If String.IsNullOrEmpty(City) Then
                        temp += ZipCode + ", "
                    Else
                        temp += ZipCode + " " + City + ", "
                    End If
                End If
            End If
            If String.IsNullOrEmpty(Country) = False Then
                temp += Country
            Else
                temp = temp.Trim
                Do While temp.EndsWith(",")
                    temp = temp.Remove(temp.Length - 1, 1)
                    temp = temp.Trim()
                Loop
            End If
            Return temp
        End Function

        Public Overridable Function ToAddress() As Address
            Return New Address With {.Addition = Addition, .City = City, .CompanyName = CompanyName, .Country = Country, .Forname = Forname, .No = No, .Salutation = Salutation, .Street = Street, .Surname = Surname, .Title = Title, .ZipCode = ZipCode}
        End Function

        Public Shared Function FromAddress(a As Address, _customerid As String) As AddressModel
            Return New AddressModel With {.CustomerID = _customerid, .Salutation = a.Salutation, .Title = a.Title, .Forname = a.Forname, .Surname = a.Surname, .Street = a.Street, .No = a.No, .Addition = a.Addition, .ZipCode = a.ZipCode, .City = a.City, .Country = a.Country, .CompanyName = a.CompanyName}
        End Function
    End Class

    Public Class EAddressModel
        Public Sub New()
        End Sub

        Public Overridable Property EAddressID As String
            Get
                Return CustomerID + "-" + AddressDescription
            End Get
            Set(value As String)

            End Set
        End Property

        Public Overridable Property CustomerID As String

        Public Overridable Property AddressDescription As String

        Public Overridable Property Salutation As String
        Public Overridable Property Title As String
        Public Overridable Property Forname As String
        Public Overridable Property Surname As String
        Public Overridable Property Street As String
        Public Overridable Property No As String
        Public Overridable Property Addition As String
        Public Overridable Property ZipCode As String
        Public Overridable Property City As String
        Public Overridable Property Country As String

        Public Overridable Property CompanyName As String

        Public Overridable Function ToEAddress() As EAddress
            Return New EAddress With {.AddressDescription = AddressDescription, .Addition = Addition, .City = City, .CompanyName = CompanyName, .Country = Country, .Forname = Forname, .No = No, .Salutation = Salutation, .Street = Street, .Surname = Surname, .Title = Title, .ZipCode = ZipCode}
        End Function

        Public Shared Function FromAddress(a As EAddress, cid As String) As EAddressModel
            Return New EAddressModel With {.CustomerID = cid, .AddressDescription = a.AddressDescription, .Salutation = a.Salutation, .Title = a.Title, .Forname = a.Forname, .Surname = a.Surname, .Street = a.Street, .No = a.No, .Addition = a.Addition, .ZipCode = a.ZipCode, .City = a.City, .Country = a.Country, .CompanyName = a.CompanyName}
        End Function
    End Class

    Public Class DeliveryAddressModel
        Public Sub New()
        End Sub
        Public Overridable Property GUID As String
        Public Overridable Property Salutation As String
        Public Overridable Property Title As String
        Public Overridable Property Forname As String
        Public Overridable Property Surname As String
        Public Overridable Property Street As String
        Public Overridable Property No As String
        Public Overridable Property Addition As String
        Public Overridable Property ZipCode As String
        Public Overridable Property City As String
        Public Overridable Property Country As String

        Public Overridable Property CompanyName As String

        Public Overridable Function ToAddress() As Address
            Return New Address With {.Addition = Addition, .City = City, .CompanyName = CompanyName, .Country = Country, .Forname = Forname, .No = No, .Salutation = Salutation, .Street = Street, .Surname = Surname, .Title = Title, .ZipCode = ZipCode}
        End Function

        Public Shared Function FromAddress(a As Address, _orderid As String) As DeliveryAddressModel
            If a IsNot Nothing Then
                Return New DeliveryAddressModel With {.GUID = _orderid, .Salutation = a.Salutation, .Title = a.Title, .Forname = a.Forname, .Surname = a.Surname, .Street = a.Street, .No = a.No, .Addition = a.Addition, .ZipCode = a.ZipCode, .City = a.City, .Country = a.Country, .CompanyName = a.CompanyName}
            End If
            Return Nothing
        End Function
    End Class

    Public Class ContactModel
        Public Sub New()
        End Sub
        Public Overridable Property CustomerID As String
        Public Overridable Property Telefon1 As String
        Public Overridable Property Telefon2 As String
        Public Overridable Property Telefax1 As String
        Public Overridable Property Telefax2 As String
        Public Overridable Property Mobil1 As String
        Public Overridable Property Mobil2 As String
        Public Overridable Property Mail1 As String
        Public Overridable Property Mail2 As String
        Public Overridable Property Facebook As String
        Public Overridable Property Twitter As String
        Public Overridable Property Website As String

        Public Overridable Function ToContact() As Contact
            Return New Contact With {.Facebook = Facebook, .Mail1 = Mail1, .Mail2 = Mail2, .Mobil1 = Mobil1, .Mobil2 = Mobil2, .Telefax1 = Telefax1, .Telefax2 = Telefax2, .Telefon1 = Telefon1, .Telefon2 = Telefon2, .Twitter = Twitter, .Website = Website}
        End Function

        Public Shared Function FromContact(c As Contact, customerid As String) As ContactModel
            Return New ContactModel With {.CustomerID = customerid, .Facebook = c.Facebook, .Mail1 = c.Mail1, .Mail2 = c.Mail2, .Mobil1 = c.Mobil1, .Mobil2 = c.Mobil2, .Telefax1 = c.Telefax1, .Telefax2 = c.Telefax2, .Telefon1 = c.Telefon1, .Telefon2 = c.Telefon2, .Twitter = c.Twitter, .Website = c.Website}
        End Function
    End Class
End Namespace
